<template>
  <default-layout>
    <header-back text="办理合格证明" slot="header"></header-back>
    <div
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="disabledScroll"
      infinite-scroll-distance="10"
      infinite-scroll-immediate-check="false"
      slot="main"
      class="list scroll-view">
      <router-link :to="`/qualified/qualified-info?applyId=${val.applyId}&yearId=${val.yearId}&handle=${encodeURIComponent(val.handle)}`" class="item" v-for="(val, key) in list" :key="key">
        <div class="top">
          <span class="tit">{{val.title}}</span>
          <span
            class="desc"
            :class="Number(val.learnStatusCode) === 1 ? 'pending' : 'success'">{{val.learnStatus}}</span>
        </div>
        <div class="bottom">
          <span class="desc">{{val.signDate}}</span>
          <mt-button type="primary" size="small" @click.prevent.stop="go(val)" v-if="Number(val.learnStatusCode) === 1">上传考试成绩</mt-button>
        </div>
      </router-link>
      <loading-text v-if="loading"></loading-text>
      <finish-text v-if="noMore"></finish-text>
      <empty v-if="empty"></empty>
      <yd-backtop></yd-backtop>
    </div>
    <transition name="router" mode="out-in">
      <router-view class="fixed-router"></router-view>
    </transition>
  </default-layout>
</template>
<script>
  import HeaderBack from '../../../components/header-back/header-back.vue'
  import LoadingText from '../../../components/loading-text/loading-text.vue'
  import FinishText from '../../../components/finish-text/finish-text.vue'
  import DefaultLayout from '../../../layouts/default-layout/default-layout'
  import {infinite} from '../../../common/js/mixin'
  import {mapGetters} from 'vuex'
  import Empty from '../../../components/empty/empty'

  export default {
    components: {
      Empty,
      DefaultLayout,
      FinishText,
      LoadingText,
      HeaderBack},
    data() {
      return {
        /* 以下五个参数为上拉加载页面必需的参数 */
        loading: true,
        page: 1,
        size: 10,
        total: 0,
        list: []
        /* 以上五个参数为上拉加载页面必需的参数 */
      }
    },
    computed: {
      ...infinite,
      ...mapGetters([
        'userInfo'
      ])
    },
    methods: {
      loadMore() {
        if (this.page === 1) this.list = []
        this.$post('/admin/person/sapi/education/continuing/get/signup/list', {
          cardId: this.userInfo.idCard,
          page: this.page,
          pageSize: this.size
        }, loading => {
          this.loading = loading
        }, false).then(res => {
          /*
          * learnStatusCode: 1学习中  2已通过
          * */
          this.list = this.list.concat(res.data.dataList)
          this.total = res.data.pageBean.totalCount
          this.page++
        }).catch(() => {
          this.list = []
        })
      },
      go(val) {
        this.$router.push({
          name: 'qualifiedUploadChild',
          query: {
            applyId: val.applyId,
            yearId: val.yearId
          }
        })
      }
    },
    created() {
      this.loadMore()
    }
  }
</script>
<style scoped lang="scss">
  @import "../../../common/style/variable";
  .list{
    background: #fff;
  }
  .item{
    padding: .2rem;
    border-bottom: 1px solid #ededed;
    display: flex;
    flex-direction: column;
    @include active;
    .tit{
      font-size: .33rem;
      color: #333;
    }
    .desc{
      font-size: .28rem;
      color: #666;
      &.pending{
        color: #666;
      }
      &.danger{
        color: $danger;
      }
      &.success{
        color: $success;
      }
    }
    .top{
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .bottom{
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      padding: .2rem 0 0 0;
    }
  }
</style>
